package me.trytofeel.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component // 通用组件，不指定角色
@MapperScan("me.trytofeel.mapper") // 扫描Mapper
public class MybatisConfig {

//    // 导入mapper的对象形式
//    @Bean
//    public MapperScannerConfigurer getMapperScannerConfigurer() {
//        MapperScannerConfigurer msc = new MapperScannerConfigurer();
//        msc.setBasePackage("me.trytofeel.mapper");
//        return msc;
//    }

    @Bean // 让Spring接管
    public SqlSessionFactoryBean getSqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); // 缩写： SSFB
        sqlSessionFactoryBean.setDataSource(dataSource);
        return sqlSessionFactoryBean;
    }
}
